Skip to content

Return post-mutation data from store ops; construct the CLI - #1

Merged
jonascript merged 2 commits into
mainfrom
refactor/store-returns-data
Jul 29, 2026
Merged

jonascript merged 2 commits into
mainfrom
refactor/store-returns-data

Conversation

@jonascript

Copy link
Copy Markdown
Owner

Store.Mutate already produced the post-mutation Data, but every operation in ops.go threw it away and returned only its own result. All three frontends then read the file a second time to recover it — and a surprising amount of this codebase turned out to be workarounds for that.

The change

Mutating ops return (result, Data, error). Add is (task.Task, Data, error), Undo is (string, Data, error). That deletes:

  • cli.quadrantLabels and mcpserver.labelsOf — two near-duplicate helpers that each did the second read and swallowed its error as "cosmetic"
  • seven copies of the same closure in the TUI, each ending in store.Load()
  • the window where the label a command printed came from a later file state than the mutation describing it

SetMCPEnabled is the deliberate exception: nothing renders from it, and handing an MCP-gated caller the whole matrix from the call that flips the gate is a poor shape.

The TUI signalled mutation failure through m.status. Two callers sniffed if m.status == "" to detect success; three overwrote it unconditionally — so a failed complete, delete, or move printed done: … over its own error while the row stayed on screen. It is now apply(d, err) bool, and success messages are set inside the branch. Because ops hand back the data, the call sites lost their closures entirely:

if _, d, err := m.store.Complete(t.ID); m.apply(d, err) {
    m.status = fmt.Sprintf("done: %s", t.DisplayTitle())
}

Input state now goes through enterInput/exitInput, closing a placeholder that leaked from a quadrant rename into the next task edit, and an editingID that cancel never cleared.

The CLI was one 310-line init() mutating a package-level rootCmd. Flag variables were process-global, and every RunE was unreachable from a test: internal/cli sat at 18.9% coverage with ike mcp enable|disable — the consent toggle for agent access — at 0%. The store-level gate was well tested; the commands users actually run to grant and revoke access were not tested at all.

Commands are now built by newXCmd(open) under NewRootCmd, print to cmd.OutOrStdout(), and share a withStore adapter that absorbed 15 copies of open-and-check. openStore, a pure pass-through wrapper, is gone. open stays lazy so ike --help still works with a broken IKE_DATA_FILE.

Coverage

package before after
internal/cli 18.9% 90.3%
internal/task 81.1% 100%
internal/mcpserver 85.9% 91.5%
internal/store 85.1% 86.1%
internal/tui 88.9% 88.9%

103 tests → 127. New regression tests pin the three status-clobbering bugs, the placeholder leak, the archive ordering contract, and the full ike mcp enable/disable/status cycle.

Folded in, because the above needed them

  • taskTool/listTool adapters in mcpserver, replacing eight byte-identical tool bodies
  • Data.List / Data.ListArchive as the single definition of each order. The TUI reversed data.Archive instead, which agrees with ListArchive only while every archived task carries a done_at
  • task.ArchiveRow, so ike archive and the TUI archive view cannot drift
  • time.RFC3339 in place of the layout written out by hand, twice
  • ops_test.go split into ops/history/labels/mcp — it crossed 1000 lines during this work; nothing in the repo is over it now

One regression, caught here

Rewriting ListArchive I reached for slices.Clone, which preserves nil — so ike archive --json emitted null instead of [] on an empty archive. A new test caught it. Reverted to make+copy with a comment, pinned by TestListArchiveIsNeverNil.

Not in scope

Left for follow-ups: the ToTop/ToBottom sentinels and the two remaining copies of direction parsing; no dupl/funlen bound in .golangci.yml; the sed-based Homebrew tap step in release.yml.

Verification

gofmt clean · go vet ./... clean · go test -race -count=1 ./... passing. No behavior change intended anywhere except the three fixed bugs.

🤖 Generated with Claude Code

jonascript and others added 2 commits July 29, 2026 01:34
Store.Mutate already produced the post-mutation Data, but every operation
threw it away and returned only its own result. All three frontends then
read the file a second time to recover it, which is where a surprising
amount of this codebase came from:

- cli.quadrantLabels and mcpserver.labelsOf, two near-duplicate helpers
  that each did that second read and swallowed its error as "cosmetic"
- seven copies of the same closure in the TUI, each ending in store.Load()
- a window where the label a command printed came from a later file state
  than the mutation it was describing

Mutating ops now return (result, Data, error). All of the above is deleted.

The TUI's mutate reported failure by writing into m.status; two callers
sniffed `if m.status == ""` to detect success and three overwrote it
unconditionally, so a failed complete, delete, or move printed "done: ..."
over its own error while the row stayed on screen. It is now
apply(d, err) bool, and success messages are set inside the branch.
Input-mode state is set and cleared through enterInput/exitInput, closing
a placeholder that leaked from a quadrant rename into the next task edit.

The CLI was one 310-line init() mutating a package-level rootCmd, which
made flag variables process-global and every RunE unreachable from a test:
internal/cli sat at 18.9% coverage with `ike mcp enable|disable` — the
consent toggle for agent access — at 0%. Commands are now constructed by
newXCmd(open) under NewRootCmd, print to cmd.OutOrStdout(), and share a
withStore adapter. openStore, a pure pass-through wrapper, is gone.

Coverage: cli 18.9% -> 90.3%, task 81.1% -> 100%, mcpserver 85.9% -> 91.5%,
store 85.1% -> 86.1%. 103 tests -> 127.

Also folded in, since the above needed them:

- taskTool/listTool adapters in mcpserver, replacing eight byte-identical
  tool bodies
- Data.List and Data.ListArchive as the single definitions of each order.
  The TUI reversed data.Archive instead, which agrees with ListArchive
  only while every archived task carries a done_at
- task.ArchiveRow, so `ike archive` and the TUI archive view cannot drift
- time.RFC3339 in place of the layout written out by hand
- ops_test.go split into ops/history/labels/mcp, keeping every file under
  1000 lines

ListArchive keeps make+copy rather than slices.Clone: Clone preserves nil,
which made `ike archive --json` emit null instead of []. Pinned by test.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
misspell runs with locale: US, so "signalling" and "cancelling" fail lint.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jonascript
jonascript merged commit 8c09b04 into main Jul 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant